package com.sayice.coursetable.ui.exam;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.sayice.coursetable.R;
import com.sayice.coursetable.logic.model.Exam;

import java.util.List;

/**
 * 考试适配器
 */
public class ExamAdapter extends RecyclerView.Adapter<ExamAdapter.ViewHolder> {
    private final List<Exam> examList;

    public static class ViewHolder extends RecyclerView.ViewHolder {
        private final TextView courseName;
        private final TextView time;
        private final TextView room;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            courseName = itemView.findViewById(R.id.courseName);
            time = itemView.findViewById(R.id.time);
            room = itemView.findViewById(R.id.room);
        }
    }

    public ExamAdapter(@NonNull List<Exam> examList) {
        this.examList = examList;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
        LayoutInflater layoutInflater = LayoutInflater.from(viewGroup.getContext());
        View view = layoutInflater.inflate(R.layout.exam_item, viewGroup, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder, int position) {
        Exam exam = examList.get(position);
        viewHolder.courseName.setText(exam.courseName);
        viewHolder.time.setText(String.valueOf(exam.time));
        viewHolder.room.setText(String.valueOf(exam.room));
    }

    @Override
    public int getItemCount() {
        return examList.size();
    }
}
